#include "iot_errno.h"
#include "iot_watchdog.h"
#include "stm32f4xx_ll_iwdg.h"
#include "stdio.h"

void IoTWatchDogEnable(void)
{
    // 写入0x00005555，允许设置与分频器和超时计数器
    LL_IWDG_EnableWriteAccess(IWDG);
    // 设置预分频器,使用32K LSI，256分配得到0.125K---8ms
    LL_IWDG_SetPrescaler(IWDG, LL_IWDG_PRESCALER_256);
    // 设置计数器，1250--->10s
    LL_IWDG_SetReloadCounter(IWDG, 1250);
    // 写入0x0000cccc启动看懵
    LL_IWDG_Enable(IWDG);
}

void IoTWatchDogKick(void)
{
    // 喂狗，其实就是写入0x0000AAAA
    LL_IWDG_ReloadCounter(IWDG);
}

void IoTWatchDogDisable(void)
{
    // 独立看门狗不能被关闭
    printf("If IWDG is working, you can not stop it any more...\n");
}

